home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / FlyPaper.sit / Fly Paper / FlyPaper Source / App Sources / patches.c < prev    next >
Text File  |  1996-06-22  |  3KB  |  89 lines

  1. // File "patches.c" -
  2.  
  3. #include <Traps.h>
  4. #include <Windows.h>
  5.  
  6. #include "patches.h"
  7. #include "FlyPaperApp.h"
  8.  
  9. // ***********************************************************************************
  10. // Global Declarations 
  11.  
  12. ExitToShellUPP gSaveExitToShell;
  13.  
  14. ExitToShellUPP gExitToShellPatch = 0;
  15. NewWindowUPP gNewWindowPatch=0;
  16.  
  17. // ***********************************************************************************
  18. // ***********************************************************************************
  19.  
  20. void PatchExitToShell() {
  21.     short trap = _ExitToShell; 
  22.     
  23.     if (! gExitToShellPatch) gExitToShellPatch = NewExitToShellProc(MyExitToShell);
  24.     if (! gExitToShellPatch) return;
  25.     
  26.     gSaveExitToShell = (ExitToShellUPP) 
  27.             NGetTrapAddress(trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  28.     NSetTrapAddress((UniversalProcPtr) gExitToShellPatch,
  29.             trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  30.     }
  31.     
  32. // ***********************************************************************************
  33. // ***********************************************************************************
  34.  
  35. pascal void MyExitToShell() {
  36.     static Boolean done = false;
  37.     long saveA5;
  38.     ExitToShellUPP tempSaveExitToShell;
  39.     
  40.     // Setup (68k) globals in case we are ES-ing from deep within Macsbug.
  41.     saveA5 = SetCurrentA5();
  42.  
  43.     // Our ExitToShell() patch may cause re-entrancy problems... so we bracket
  44.     //   the functional calls by checking and setting a one-time flag.
  45.     if (! done) {
  46.         done = true;
  47.         Finalize ();
  48.         }
  49.  
  50.     // Save off the global pointer while we still have our 68K A5-World set up
  51.     tempSaveExitToShell = gSaveExitToShell;
  52.     SetA5(saveA5);
  53.     
  54.     CallExitToShellProc(tempSaveExitToShell);
  55.     }
  56.  
  57. // ***********************************************************************************
  58. // ***********************************************************************************
  59.  
  60. void PatchNewWindow(void) {
  61.     short trap = _NewWindow; 
  62.  
  63.     if (! gNewWindowPatch) gNewWindowPatch = NewNewWindowProc(MyNewWindow);
  64.     if (! gNewWindowPatch) return;
  65.     
  66.     NSetTrapAddress((UniversalProcPtr) gNewWindowPatch,
  67.             trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  68.     }
  69.     
  70. // ***********************************************************************************
  71. // ***********************************************************************************
  72.  
  73. pascal WindowPtr MyNewWindow(Ptr wStorage, Rect *bounds, StringPtr title,
  74.         Boolean vis, short procID, WindowPtr behind, Boolean close, long refCon) {
  75.     short trap = _NewCWindow;
  76.     WindowPtr win;
  77.     NewWindowUPP myNewCWindow;
  78.     
  79.     // Call NewCWindow in place of NewWindow!
  80.     myNewCWindow = (NewWindowUPP) 
  81.             NGetTrapAddress(trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  82.     
  83.     win = CallNewWindowProc(myNewCWindow, wStorage, bounds, title, vis, procID,
  84.             behind, close, refCon);
  85.  
  86.     return(win);
  87.     }
  88.  
  89.